package com.action.link;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.link.Link;
import com.business.link.LinkBus;
import com.config.SystemGlobals;

public class ManageLink extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
	
		if (request.getParameter("deleted") != null) {
			String[] logNos = request.getParameterValues("deleted");
			LinkBus lb = new LinkBus();
			lb.del(logNos);
			out
					.println("<script>alert(\"删除链接成功\");window.location=\"admin/blog/linklist.jsp\";</script>");
			out.close();
		}
	if (request.getParameter("edit") != null) {
		String name = request.getParameter("linkname");
		String url = request.getParameter("linkurl");
		String demo = request.getParameter("linkdemo");
		String isShow = request.getParameter("isshow");
		
		if(isShow==null) {
			isShow="0";
		}
		String username=request.getParameter("username");
		Link link=new Link();
		link.setIsShow(isShow);
		link.setLinkDemo(demo);
		link.setLinkName(name);
		link.setLinkUrl(url);
		link.setUsername(username);
		
		String linkNo = request.getParameter("no");
		LinkBus lb=new LinkBus();
		lb.update(link, linkNo);
			out
					.println("<script>alert(\"修改链接成功\");window.location=\"admin/blog/linklist.jsp\";</script>");
			out.close();
		}
	}

	}

